package study.gateway.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import java.util.HashMap;
import java.util.Map;

@RestController
public class GlobalController {
    /**
     * 路由找不到控制器，配合
     */
    @RequestMapping("/notfound")
    public Mono<Map<String,String>> notFound(){
        Map<String,String> map = new HashMap<>();
        map.put("code","404");
        map.put("data","Not Found");
        return Mono.just(map);
    }
    /**
     * 路由定义的服务异常控制器
     */
    @RequestMapping("/fallback")
    public Mono<Map<String,String>> ServiceNotAvailable (){
        Map<String,String> map = new HashMap<>();
        map.put("code","100");
        map.put("data","Service Not Available");
        return Mono.just(map);
    }


    /**
     * 权重路由测试 - V1
     */
    @RequestMapping("/v1")
    public Mono<String> server1 (){
        return Mono.just("权重路由测试 - V1");
    }
    /**
     * 权重路由测试 - V2
     */
    @RequestMapping("/v2")
    public Mono<String> server2 (){
        return Mono.just("权重路由测试 - V2");
    }
}
